import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

import constantRoutesList from './modules/constantRoutesList' // 无权限要求路由列表
import home from './modules/home' // 首页路由
import needList from './modules/needList' // 首页路由
import assessment from './modules/assessment'// 经理考核
import fundManager from './modules/fundManager'// 基金经理
import maintain from './modules/maintain'// 机构维护
import adminSystem from './modules/admiSystem'// 系统管理
import infoMain from './modules/infoMain'// 变更记录
import newspaper from './modules/newspaper'// 报社维护
import integratedQuery from './modules/integratedQuery'// 产品综合查询
import fundDataExport from './modules/fundDataExport'// 基金数据导出
import InformationAudit from './modules/InformationAudit'// 风控信息审核
import { redirectQueue } from './modules/redirectQueue'// 重定向路由列表
// ----------------基于权限逻辑，所有路由都必须放入这两个容器---------------
/**
 * constantRoutes
 * 没有权限要求的基本页面，所有角色可以访问
 */
export const constantRoutes = [
	...integratedQuery,
	...constantRoutesList
	// transaction
]

/**
 * 异步路由
 * 需要根据用户角色动态加载的路由
 */
export const asyncRoutes = [
	...redirectQueue,
	...home,
	...needList,
	...infoMain,
	...fundManager,
	...assessment,
	...maintain,
	...newspaper,
	...fundDataExport,
	...InformationAudit,
	...adminSystem,
	// permission,
	// 报错页面公共配置 !!!
	{ path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
	mode: 'history', // 需要服务支持
	base: window.__MICRO_APP_BASE_ROUTE__ || process.env.BASE_URL,
	scrollBehavior: () => ({ y: 0 }),
	routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
	const newRouter = createRouter()
	router.matcher = newRouter.matcher // 重置路由器
}

export default router
